
<div class="layui-fluid">
    <div class="layui-row">
        <form class="layui-form">
            <div class="layui-form-item">
                <label for="title" class="layui-form-label">
                    <span class="x-red">*</span>角色名
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="title"  name="title" value="{$edit.title}" required="" lay-verify="required"
                           autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="title" class="layui-form-label">
                    选择权限
                </label>
                <div class="layui-input-inline">
                    <div id="LAY-auth-tree-index"></div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <input type="hidden" name="id" value="{$edit.id}">
                    <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </form>
    </div>
</div>
<script type="text/javascript">
    layui.config({
        base: '/static/extends/',
    }).extend({
        authtree: 'authTree/authtree',
    });
    layui.use(["form", "authtree", "jquery"], function () {
        let form = layui.form
            , authtree = layui.authtree
            , jq = layui.jquery;

        jq.get("{:url('menu/getTreeAll')}", function (res) {
            authtree.render(
                '#LAY-auth-tree-index',
                res.data, {
                    inputname: 'authids[]',
                    layfilter: 'lay-check-auth',
                    autowidth: true,
                    checkedKey:[{$edit.rule}]
                });
        });

        form.on('submit(formDemo)', function (obj) {
            //console.log(obj.field);
            //return false;
            $.post("{:url('save')}", obj.field, function (res) {
                if (res.code == {$result.normal}) {
                    hadmin.father_reload();
                }
            })
            return false;
        })
    });
</script>
